/**
 * 
 */
package com.tao.util;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;

/**
 * @author davidli
 *
 */
public class JacksonUtils {
	
	/**
	 * A common method for all Json String to HashMap
	 * @param String Json format
	 * @return HashMap, or null
	 */
	public static Map<String,String> json2Map(String json) throws Exception{
		Map<String,String> resultMap = new HashMap<String,String>();
	    if(!StringUtils.isEmpty(json)) {
        	ObjectMapper mapper = new ObjectMapper();
		    TypeReference<HashMap<String,String>> typeRef = new TypeReference<HashMap<String,String>>(){}; 
		    resultMap = mapper.readValue(json, typeRef); 
			
	    }
	    return resultMap;
	}
	
	
}
